/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.teamreinforce.logic.model;

import com.teamreinforce.logic.beans.CollaborateurFacade;
import com.teamreinforce.logic.entities.Collaborateur;
import com.teamreinforce.logic.entities.Tache;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author tidiane
 */
@Stateless
public class Model implements IModel {

    @PersistenceContext (unitName = "TeamReinforceAppPU")
    private EntityManager em;
    
    @Override
    public int login(String login, String password) {
        TypedQuery<Collaborateur> query = em.createNamedQuery("Collaborateur.findByLogin", Collaborateur.class);
            query.setParameter("login", login);
            try {
                Collaborateur c = query.getSingleResult();
                if ( c.getPassword().equals(password)){
                    return c.getIdCollaborateur();
                }
                else return -1;
            }
            catch (Exception e){
                return -1;
            }
        }
    
}
